<template>
  <PageContainer>
    <Header title="编辑名片" />
    <view v-if="botCardInfo" class="hb-p-4 hb-flex hb-flex-col hb-gap-3">
      <BasicInfo :botCardInfo="botCardInfo" @success="queryCardInfo" />
      <ContactInfo :botCardInfo="botCardInfo" @success="queryCardInfo" />
      <CompanyInfo :botCardInfo="botCardInfo" @success="queryCardInfo" />
      <ProductService :botCardInfo="botCardInfo" @success="queryCardInfo" />
      <AttachmentDocs :botCardInfo="botCardInfo" @success="queryCardInfo" />

      <BottomSubmit submitBtnLabel="预览名片" :submitBtnColor="'#2878FF'" @submit="handlePreview" />
    </view>
  </PageContainer>
</template>

<script lang="ts" setup>
  /* cardEdit 编辑名片 */
  import BasicInfo from './components/BasicInfo.vue';
  import ContactInfo from './components/ContactInfo.vue';
  import CompanyInfo from './components/CompanyInfo.vue';
  import ProductService from './components/ProductService.vue';
  import AttachmentDocs from './components/AttachmentDocs.vue';
  import { getByIdInfo } from '@/api/card';
  import { BotCardInfo } from '@/api/card/type';
  import { useUserStore } from '@/store/modules/user';
  let success: () => void;
  customOnload<'CardEdit'>((options) => {
    success = options.success;
    queryCardInfo();
  });

  const userStore = useUserStore();
  const botCardInfo = ref<BotCardInfo>();
  const queryCardInfo = async () => {
    const res = await getByIdInfo();
    botCardInfo.value = res;
    success?.();
  };

  const handlePreview = () => {
    navigateTo({
      name: 'cardDetail',
      options: {
        uuid: userStore.uuid!,
      },
    });
  };
</script>

<style lang="scss" scoped>
  /* 使用Windi CSS，无需额外样式 */
</style>
